#include <stdio.h>
#include <malloc.h>
#include "star_types.h"

int len_of_StarSystemList(StarSystemListNode *starSystemList)
{
    StarSystemListNode *p = starSystemList;
    int i = 0;
    while (p != NULL)
    {
        p = p->next;
        i++;
    }
    return i;
}

int len_of_StarshipList(StarshipListNode *starshipSystemList)
{
    StarSystemListNode *p = starshipSystemList;
    int i = 0;
    while (p != NULL)
    {
        p = p->next;
        i++;
    }
    return i;
}

StarSystemListNode *getNumberOfSystemList(StarSystemListNode *starSystemListNode, int number)
{
    StarSystemListNode *p = starSystemListNode;
    int i = 0;
    while (p != NULL)
    {
        if (i == number)
        {
            return p;
        }
        p = p->next;
        i++;
    }
    return NULL;
}

StarshipListNode *getNumberOfShipList(StarshipListNode *starshipListNode, int number)
{
    StarshipListNode *p = starshipListNode;
    int i = 0;
    while (p != NULL)
    {
        if (i == number)
        {
            return p;
        }
        p = p->next;
        i++;
    }
    return NULL;
}

void free_StarShipList(StarshipListNode *starshipListNode)
{
    StarshipListNode *p, *last = starshipListNode;
    while (p != NULL)
    {
        last = p;
        p = p->next;
        free(last);
    }
    free(last);
}

void free_StarSystemListNode(StarSystemListNode *starSystemListNode)
{
    StarSystemListNode *p, *last = starSystemListNode;
    while (p != NULL)
    {
        last = p;
        p = p->next;
        free(last);
    }
    free(last);
}
